/** @format */

import { createApp } from 'vue';
import './style.css';
// import naive from 'naive-ui';
import ElementPlus from 'element-plus';
import 'element-plus/dist/index.css';
import { createPinia } from 'pinia';
import * as ElementPlusIconsVue from '@element-plus/icons-vue';
import VConsole from 'vconsole';
import loadingInstance from './utils/loadin.js'; // 加载动画loading
import App from './App.vue';
import Vant from "vant";
import router from './router/index.js';
import './style.css';
console.log(loadingInstance, 'loadingInstance');
const vConsole = new VConsole();
// 创建 Pinia 实例
const pinia = createPinia();
const app = createApp(App);
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
    app.component(key, component);
}
app.use(ElementPlus);
app.use(vConsole);
app.use(router);
app.use(pinia);
app.use(Vant);
app.mount('#app');
app.directive('long-press', {
    // 使用 Vue 3 的钩子
    beforeMount(el, binding) {
        let timer;
        const duration = 1000; // 设置长按时间阈值

        // 确保传递的值是函数
        if (typeof binding.value !== 'function') {
            console.warn('v-long-press 指令需要传入一个函数作为回调');
            return;
        }

        // 监听 touchstart 事件
        el.addEventListener('touchstart', () => {
            console.log('touchstart');
            timer = setTimeout(() => {
                binding.value(); // 执行传入的回调函数
            }, duration);
        });

        // 监听 touchend 事件
        el.addEventListener('touchend', () => {
            console.log('touchend');
            clearTimeout(timer); // 长按结束时清除定时器
        });

        // 监听 touchmove 事件，防止滑动时误触发
        el.addEventListener('touchmove', () => {
            console.log('touchmove');
            clearTimeout(timer); // 长按过程中如果发生滑动，清除定时器
        });
    },
});
console.log(app, 'app');

app.config.$pageLoading = loadingInstance;

export const getVm = () => app.config;
